package com.chen.controller;

import com.chen.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/response")
public class ControllerResponse {

    //响应页面~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //字符串
    @RequestMapping("/test1")
    public String test1(){
        return "info";
    }

    //ModelAndView
    @RequestMapping("/test2")
    public ModelAndView test2(ModelAndView modelAndView){
        User user = new User();
        modelAndView.addObject(user);
        modelAndView.setViewName("info");
        return modelAndView;
    }

    //响应数据~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //响应字符串
    @RequestMapping("/test3")
    @ResponseBody
    public String test3(){
        return "hello";
    }

    //响应对象或集合(自动将对象转为json)
    @RequestMapping("/test4")
    @ResponseBody
    public User test4(){
        User user = new User("张三疯", "122");
        return user;
    }
}
